home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 8.5 KB | 293 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWBWPat.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #if defined(FW_PROFILER_CALLS) && defined(__MWERKS__)
- #pragma profile on
- #endif
-
- #ifndef FWBWPAT_H
- #include "FWBWPat.h"
- #endif
-
- #ifndef FWGRGLOB_H
- #include "FWGrGlob.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgraphx
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CBWPatternRep, FW_CPatternRep)
-
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LBWPatternRep, FW_CBWPatternRep, FW_CBWPatternRep::Read, FW_CPatternRep::Write)
-
- //========================================================================================
- // CLASS FW_CBWPatternRep
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::FW_CBWPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CBWPatternRep::FW_CBWPatternRep()
- {
- unsigned char black[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- MoveBitPattern(black, &fBitPattern);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::FW_CBWPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CBWPatternRep::FW_CBWPatternRep(const FW_BitPattern& bits)
- {
- MoveBitPattern(&bits, &fBitPattern);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::FW_CBWPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CBWPatternRep::FW_CBWPatternRep(FW_CReadableStream& stream)
- {
- stream.Read(fBitPattern.fData, 8);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::~FW_CBWPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CBWPatternRep::~FW_CBWPatternRep()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::Invert
- //----------------------------------------------------------------------------------------
-
- void FW_CBWPatternRep::Invert()
- {
- *((long*)&fBitPattern.fData[0]) ^= 0xFFFFFFFFL;
- *((long*)&fBitPattern.fData[4]) ^= 0xFFFFFFFFL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::FlipVerticaly
- //----------------------------------------------------------------------------------------
-
- void FW_CBWPatternRep::FlipVerticaly()
- {
- for (short i = 0; i<4; i++)
- {
- unsigned char temp = fBitPattern.fData[i];
- fBitPattern.fData[i] = fBitPattern.fData[7-i];
- fBitPattern.fData[7-i] = temp;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::FlipHorizontaly
- //----------------------------------------------------------------------------------------
- // This is not the best implementation
-
- void FW_CBWPatternRep::FlipHorizontaly()
- {
- for (short j = 0; j<8; j++)
- {
- unsigned char leftMask = 0x80;
- unsigned char rightMask = 0x01;
- unsigned char theChar = fBitPattern.fData[j];
- for (short i = 0; i<4; i++)
- {
- unsigned char left = theChar & leftMask;
- unsigned char right = theChar & rightMask;
-
- if (left)
- theChar |= rightMask; // Set
- else
- theChar ^= right; // Clear
-
- if (right)
- theChar |= leftMask; // Set
- else
- theChar ^= left; // Clear
-
- leftMask >>= 1;
- rightMask <<= 1;
- }
- fBitPattern.fData[j] = theChar;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::ShiftRight
- //----------------------------------------------------------------------------------------
-
- void FW_CBWPatternRep::ShiftRight()
- {
- for (short i = 0; i<8; i++)
- {
- unsigned char theChar = fBitPattern.fData[i];
- theChar >>= 1;
- if (fBitPattern.fData[i] & 0x01)
- theChar |= 0x80;
- fBitPattern.fData[i] = theChar;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::ShiftLeft
- //----------------------------------------------------------------------------------------
-
- void FW_CBWPatternRep::ShiftLeft()
- {
- for (short i = 0; i<8; i++)
- {
- unsigned char theChar = fBitPattern.fData[i];
- theChar <<= 1;
- if (fBitPattern.fData[i] & 0x80)
- theChar |= 0x01;
- fBitPattern.fData[i] = theChar;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::ShiftUp
- //----------------------------------------------------------------------------------------
-
- void FW_CBWPatternRep::ShiftUp()
- {
- unsigned char temp = fBitPattern.fData[0];
- for (short i = 0; i<7; i++)
- fBitPattern.fData[i] = fBitPattern.fData[i+1];
- fBitPattern.fData[7] = temp;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::ShiftDown
- //----------------------------------------------------------------------------------------
-
- void FW_CBWPatternRep::ShiftDown()
- {
- unsigned char temp = fBitPattern.fData[7];
- for (short i = 7; i>0; i--)
- fBitPattern.fData[i] = fBitPattern.fData[i-1];
- fBitPattern.fData[0] = temp;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::IsEqual
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CBWPatternRep::IsEqual(const FW_CGraphicCountedPtrRep* other) const
- {
- if (other == this)
- return TRUE;
-
- FW_CBWPatternRep* patternRep = FW_DYNAMIC_CAST(FW_CBWPatternRep, other);
-
- if (patternRep)
- {
- for (short i=0; i<7; i++)
- if (fBitPattern.fData[i] != patternRep->fBitPattern.fData[i])
- return FALSE;
- return TRUE;
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::IsBlack
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CBWPatternRep::IsBlack() const
- {
- return fBitPattern.fDataLongs[0] == 0xFFFFFFFFL && fBitPattern.fDataLongs[1] == 0xFFFFFFFFL;
- }
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::WinCreatePatternBrush
- //----------------------------------------------------------------------------------------
-
- HBRUSH FW_CBWPatternRep::WinCreatePatternBrush() const
- {
- unsigned char temp[16]; // 16 because rowbytes has to be even
- for (short i=0; i<8; i++)
- temp[2*i] = fBitPattern.fData[i] ^ 0xFF;
-
- HBRUSH hBrush = NULL;
-
- HBITMAP hbmp = ::CreateBitmap(8, 8, 1, 1, temp);
- if(hbmp != NULL)
- {
- hBrush = ::CreatePatternBrush(hbmp);
- ::DeleteObject(hbmp);
- }
-
- return hBrush;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::Copy
- //----------------------------------------------------------------------------------------
-
- FW_PPattern FW_CBWPatternRep::Copy() const
- {
- return FW_PPattern(fBitPattern);
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::MacSetInCurPort
- //----------------------------------------------------------------------------------------
-
- void FW_CBWPatternRep::MacSetInCurPort() const
- {
- ::PenPat((const Pattern*)&fBitPattern);
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CBWPatternRep::Flatten(FW_CWritableStream& archive) const
- {
- archive.Write(fBitPattern.fData, 8);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBWPatternRep::Read
- //----------------------------------------------------------------------------------------
-
- void* FW_CBWPatternRep::Read(FW_CReadableStream& archive)
- {
- return new FW_CBWPatternRep(archive);
- }
-
-